<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link href="<%=path%>/CSS/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<%@ include file="/WEB-INF/JSP/ajax.jsp"%>
<script type="text/javascript"
	src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
.seachform li label {line-height: 45px;color: #444444}
.scinput {line-height: 10px;margin-top: 5px}
.scinput1 {margin-top: 5px;height: 30px;}
.scbtn {background: #57a0ff;border-radius: 20px;width: 110px;margin-top: 4px;height: 35px}
thead {background: #f2f2f2}
.tablelist2 th {height: 45px;background: none;}
.tablelist2 tr{height:45px;}
.tablelist2 tr th{height: 20px;border-left: 1px solid #dddee6;border-right: 1px solid #dddee6;color: #444444;text-align: center;}
.tou{background: #e4eafe}
.kh{border-bottom: 1px solid #dddee6;}
.shuju td{border-left: 1px solid #dddee6;border-right: 1px solid #dddee6;color: #787c88;text-align: center;}
.shuju:nth-child(odd){background: #ffffff}
.shuju:nth-child(even){background: #f3f5fb}
.shuju:last-child{border-bottom: 1px solid #dddee6;}
.shuju:HOVER {
	background: #fff6cd;
}
 .loading {
            margin: 200px 600px;
            display: block;
            width: 65px;
            height: 65px;
            border: 1px solid #ddd;
            border-radius: 5px;
            opacity: .7;
	 background: url(<%=path%>/images/loading.gif) no-repeat;
        }

.scbtn {
	outline: none;
}
</style>
</head>
<body style="background: #f5f5f5;padding: 0 10px;">
	<div class="place" style="background: #f5f5f5; margin-top: 10px">
		<ul class="placeul">
			<li><a href="#">报表</a></li>
			<li><a href="#">财务报表</a></li>
			<li><a href="<%=path%>/DrivingSys/queryTrainCollect/look.action">培训收退费汇总表</a></li>
		</ul>
	</div>

	<div class="rightinfo"
		style="background: #fff; border-radius: 10px; height: 45px;">

		<form action="<%=path%>/DrivingSys/outXls" class="form" method="post" >
			<ul class="seachform">
				<li><label>开始时间</label><input class="scinput1" name="beginTime"
					type="text"
					onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}',dateFmt:'yyyy-MM-dd'})"
					id="datemin" class="input-text Wdate" style="width: 150px;"
					value="${beginTime}"></li>
				<li><label>结束时间</label><input class="scinput1" name="endTime"
											  type="text"
											  onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',dateFmt:'yyyy-MM-dd'})"
											  id="datemax" class="input-text Wdate" style="width: 150px;"
											  value="${endTime}">
				    <input type="hidden" name="xls" id="xls" value="">
					<input type="hidden" name="fileNames" value="培训收、退费汇总表">
					<input type="hidden" id="stu">					
			  </li>
				<li><label>&nbsp;</label><input name="" type="button"
												class="scbtn" value="立即查询" id="cx"/></li>
				<shiro:hasPermission name="/outXlsTrainCollect">
					<li><label>&nbsp;</label><input onclick="chargeCss()" type="submit" id="dc"
													class="scbtn" value="导出Excel" /></li>
				</shiro:hasPermission>
			</ul>
		</form>
	</div>

	<div style="width: 100%; overflow: auto; margin-bottom: 20px; margin-top: 30px; background: #fff; box-shadow: 0 0 10px #f2f2f2; min-height: 600px" class="div">
		<table class="tablelist2" style="width: 100%"id="table1">
			<!-- <tr class="tou">
				<th rowspan="2" width="130px">时间</th>
				<th colspan="5" class="kh">收费金额</th>
				<th colspan="4" class="kh">退、扣费金额</th>
				<th colspan="2" class="kh">考前训练收费</th>
				<th rowspan="2">其他杂费</th>
				<th rowspan="2">实收总额</th>
				<th rowspan="2">欠费总额</th>
			</tr>
			<tr class="tou">
				<th>人数</th>
				<th>培训费</th>
				<th>规费</th>
				<th>计时卡</th>
				<th>小计</th>
				<th>人数</th>
				<th>退费</th>
				<th>扣款</th>
				<th>小计</th>
				<th>科二</th>
				<th>科三</th>
			</tr> -->
		</table>
	</div>
	<div id="hidden" style="display: none">
	
	</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
	$('#table1').html("<tr><td class='loading'></td></tr>");
	var startTime = "${beginTime}"
	var endTime = "${endTime}"
	var str = '';
	str += '<tr class="tou" style="display: none;"><th colspan="15" style="height:40px">培训收、退费汇总表</th></tr>'
	str += '<tr class="tou" style="display: none">'
	str += '<th colspan="15" style="height:30px">时间：'+startTime+'至'+endTime+'</th></tr>'
	str += '<tr class="tou"><th rowspan="2" width="130px">时间</th><th colspan="5" class="kh" style="height:20px">收费金额</th>'
	str += '<th colspan="4" class="kh">退、扣费金额</th><th colspan="2" class="kh">考前训练收费</th>'
	str += '<th rowspan="2" id="other">其他杂费</th><th rowspan="2" id="ze">实收总额</th><th rowspan="2" id="qf">欠费总额</th>'
	str += '<tr class="tou"><th style="height:20px">人数</th><th>培训费</th><th>规费</th><th>计时卡</th><th>小计</th>'
	str += '<th>人数</th><th>退费</th><th>扣款</th><th>小计</th><th>科二</th><th>科三</th>'
	$.ajax({
		url: '<%=path%>/DrivingSys/queryCollectDataByTime',
	    type: "post",
	    data: {'startTime':startTime,'endTime':endTime},
	    dataType: "json",
	    async: true,
	    success:function(json){
	        data(json,str)
	        //计算合计
	       	js();
	    },
	    error:function(){
	    	$(".loading").remove();
	    	alert("错误")
	    }
	})
})

//改变样式
function chargeCss(){
	$("#hidden").html($(".div").html())
	$("#hidden table .tou th:nth-child(2)").css("width","15px");
	$("#hidden table .tou th:nth-child(1)").css("width","16px");
	$("#hidden table .tou th:nth-child(0)").css("width","16px");
	$("#hidden table .tou th").css("text-align","center");
	
	$("#hidden #other").css("width","15px")
	$("#hidden #ze").css("width","14px")
	$("#hidden #qf").css("width","18px")
	
	$("#hidden .shuju td:odd").css("text-align","center");
	$("#hidden .shuju td:even").css("text-align","center");
	
	$("#hidden .shuju td:last").css("height","23px");
	$("#hidden #hjshuju td").css("background","rgb(255,193,133)");
	
	$("#hidden table tr th").css("font-weight","bold"); 
	$("#hidden .shuju td").css("font-size","11pt");
	$("#hidden .tou th").css("font-size","11pt");
	
	$("#hidden .tou th").css("background","rgb(228,234,254)");
	$("#xls").val($("#hidden").html())
}

//根据时间查询
$("#cx").click(function(){
	var startTime = $("#datemin").val();
	var endTime = $("#datemax").val();
	if(startTime == null || startTime == ''){
		alert("开始时间不能未空")
		return false
	}
	if(endTime == null || endTime == ''){
		alert("结束时间不能未空")
		return false
	}
	$('#table1').html("<tr><td class='loading'></td></tr>");
	var str = '';
	str += '<tr class="tou" style="display: none;"><th colspan="15" style="height:40px">培训收、退费汇总表</th></tr>'
	str += '<tr class="tou" style="display: none">'
	str += '<th colspan="15" style="height:30px">时间：'+startTime+'至'+endTime+'</th></tr>'
	str += '<tr class="tou"><th rowspan="2" width="130px">时间</th><th colspan="5" class="kh" style="height:20px">收费金额</th>'
	str += '<th colspan="4" class="kh">退、扣费金额</th><th colspan="2" class="kh">考前训练收费</th>'
	str += '<th rowspan="2" id="other">其他杂费</th><th rowspan="2" id="ze">实收总额</th><th rowspan="2" id="qf">欠费总额</th>'
	str += '<tr class="tou"><th style="height:20px">人数</th><th>培训费</th><th>规费</th><th>计时卡</th><th>小计</th>'
	str += '<th>人数</th><th>退费</th><th>扣款</th><th>小计</th><th>科二</th><th>科三</th>'
	$.ajax({
		url: '<%=path%>/DrivingSys/queryCollectDataByTime',
        type: "post",
        data: {'startTime':startTime,'endTime':endTime},
        dataType: "json",
        async: true,
        success:function(json){
        	data(json,str)
        	//计算合计
        	js();
        },
        error:function(){
        	$(".loading").remove();
        	alert("错误")
        }
	})
})
//放入数据
function data(json,str){
	var pxsf2 = 0;//培训收费长度
	var gf = 0;//规费长度
	var jsk = 0;//计时卡长度
	var tkf = 0;//退、扣费金额长度
	var kmekqxl = 0;//科目二考前训练长度
	var kmskqxl = 0;//科目三考前训练长度
	var qtzf = 0;//其他杂费长度
	var bksf = 0;//补考收费长度
	var zbsfd = 0;//转班收费单长度
	var zbtfd = 0;//转班退费单长度
	for(var i=0;i<json.time.length;i++){
		var xj = 0;//培训小计
		var tkfzj = 0;//退、扣费金额小计
		var sjze = 0;//实收总额
		var qfje = 0;//欠费金额
		str += '<tr class="shuju"><td>'+json.time[i]+'</td>'//取出时间
		//放入人数，培训费
		if(json.pxsf == null || json.pxsf.length == 0){
			 str += '<td>0</td>'
			 str += '<td>0</td>'
		}else{
			if(pxsf2 >= json.pxsf.length){
				 str += '<td>0</td>'
				 str += '<td>0</td>'
			}else{
				if(json.time[i] == json.pxsf[pxsf2].dayTime){
    				if(json.pxsf[pxsf2].num == null){
    					str += '<td>0</td>'
    				}else{
    					str += '<td class="pxrs">'+json.pxsf[pxsf2].num+'</td>'
    				}
    				if(json.pxsf[pxsf2].money == null){
    					str += '<td>0</td>'
    				}else{
    					str += '<td class="pxf">'+json.pxsf[pxsf2].money+'</td>'
    					xj = xj + json.pxsf[pxsf2].money*1
    				}
    				//计算欠费金额
    				if(json.pxsf[pxsf2].qfje != null){
    					qfje = qfje + json.pxsf[pxsf2].qfje*1
    				}
    				pxsf2 = pxsf2*1+1;
    			}else{
    				 str += '<td>0</td>'
            		 str += '<td>0</td>'
    			}
			}
		}
		//放入规费
		if(json.gf == null || json.gf.length == 0){
			 str += '<td>0</td>'
		}else{
			if(gf >= json.gf.length){
				str += '<td>0</td>'
			}else{
				if(json.time[i] == json.gf[gf].dayTime){
       				 str += '<td class="gf">'+json.gf[gf].money+'</td>'
       				 xj = xj + json.gf[gf].money*1
       				 gf = gf*1+1;
   				}else{
   				 	str += '<td>0</td>'
   				}
			}
		}
		//放入计时卡
		if(json.jsk == null || json.jsk.length == 0){
			str += '<td>0</td>'
		}else{
			if(jsk >= json.jsk.length){
				str += '<td>0</td>'
			}else{
				if(json.time[i] == json.jsk[jsk].dayTime){
        			str += '<td class="jsk">'+json.jsk[jsk].money+'</td>'
        			xj = xj + json.jsk[jsk].money*1
        			jsk = jsk*1+1;
        		}else{
        			str += '<td>0</td>'
        		}
			}
		}
		str += '<td class="pxxj">'+xj+'</td>'
		//放入退、扣费金额
		if(json.tkfje == null || json.tkfje.length == 0){
			str += '<td>0</td>'
			str += '<td>0</td>'
			str += '<td>0</td>'
		}else{
			if(tkf >= json.tkfje.length){
				str += '<td>0</td>'
        		str += '<td>0</td>'
        		str += '<td>0</td>'
			}else{
				if(json.time[i] == json.tkfje[tkf].dayTime){
					if(json.tkfje[tkf].num == null){
						str += '<td>0</td>'
					}else{
						str += '<td class="tfrs">'+json.tkfje[tkf].num+'</td>'
					}
					if(json.tkfje[tkf].money == null){
						str += '<td>0</td>'
					}else{
						str += '<td class="tf">'+json.tkfje[tkf].money+'</td>'
						tkfzj = tkfzj + json.tkfje[tkf].money*1;
					}
					if(json.tkfje[tkf].withhold == null){
						str += '<td>0</td>'
					}else{
						str += '<td class="kk">'+json.tkfje[tkf].withhold+'</td>'
						//tkfzj = tkfzj + json.tkfje[tkf].withhold*1;
					}
					tkf = tkf*1+1;
				}else{
					str += '<td>0</td>'
                	str += '<td>0</td>'
                	str += '<td>0</td>'
				}
			}
		}
		str += '<td class="kkxj">'+tkfzj+'</td>'
		/*放入考前训练收费*/
		//科目二
		if(json.kqxlsfkm2 == null || json.kqxlsfkm2.length == 0){
			str += '<td>0</td>'
		}else{
			if(kmekqxl >= json.kqxlsfkm2.length){
				str += '<td>0</td>'
			}else{
				if(json.time[i] == json.kqxlsfkm2[kmekqxl].dayTime){
					if(json.kqxlsfkm2[kmekqxl].money == null){
						str += '<td>0</td>'
					}else{
						str += '<td class="ke">'+json.kqxlsfkm2[kmekqxl].money+'</td>'
    					sjze = sjze + json.kqxlsfkm2[kmekqxl].money*1	
					}
				}else{
					str += '<td>0</td>'
				}
			}
		}
		//科目三
		if(json.kqxlsfkm3 == null || json.kqxlsfkm3.length == 0){
			str += '<td>0</td>'
		}else{
			if(kmskqxl >= json.kqxlsfkm3.length){
				str += '<td>0</td>'
			}else{
				if(json.time[i] == json.kqxlsfkm3[kmskqxl].dayTime){
					if(json.kqxlsfkm3[kmskqxl].money == null){
						str += '<td>0</td>'
					}else{
						str += '<td class="ks">'+json.kqxlsfkm3[kmskqxl].money+'</td>'
    					sjze = sjze + json.kqxlsfkm3[kmskqxl].money*1
					}
				}else{
					str += '<td>0</td>'
				}
			}
		}
		//放入其他杂费
		if(json.qtzf == null || json.qtzf.length == 0){
			str += '<td>0</td>'
		}else{
			if(qtzf >= json.qtzf.length){
				str += '<td>0</td>'
			}else{
				if(json.time[i] == json.qtzf[qtzf].dayTime){
					str += '<td class="zf">'+json.qtzf[qtzf].money+'</td>'
					sjze = sjze + json.qtzf[qtzf].money*1
				}else{
					str += '<td>0</td>'
				}
			}
		}
		//放入实收总额
		sjze = sjze + tkfzj + xj;
		str += '<td class="sjze">'+sjze+'</td>'
		//欠费总额
		str += '<td class="qfje">'+qfje+'</td>'
		str += '</tr>'
	}
	str +='<tr class="shuju" style="background:#ffc185" id="hjshuju"><td>合计</td><td id="pxrs"></td><td id="pxf"></td><td id="gf"></td><td id="jsk"></td><td id="pxxj"></td>'
	str +='<td id="tfrx"></td><td id="tf"></td><td id="kk"></td><td id="tkxj"></td>'
	str +='<td id="ke"></td><td id="ks"></td><td id="qtzf"></td><td id="shze"></td><td id="qfze"></td></tr>'
	$('#table1').html(str);
}


//计算合计
function js (){
	//计算培训人数
	var pxrs = 0;
	$(".pxrs").each(function(i){
		pxrs = pxrs + $(this).text()*1;
	})
	pxrs = decimal(pxrs,2)
	$("#pxrs").text(pxrs)
	//计算培训费
	var pxf = 0;
	$(".pxf").each(function(i){
		pxf = pxf + $(this).text()*1;
	})
	pxf = decimal(pxf,2)
	$("#pxf").text(pxf)
	//计算规费
	var gf = 0;
	$(".gf").each(function(i){
		gf = gf + $(this).text()*1;
	})
	gf = decimal(gf,2)
	$("#gf").text(gf)
	//计算计时卡
	var jsk = 0;
	$(".jsk").each(function(i){
		jsk = jsk + $(this).text()*1;
	})
	jsk = decimal(jsk,2)
	$("#jsk").text(jsk)
	//计算培训收费小计
	var pxxj = 0;
	$(".pxxj").each(function(i){
		pxxj = pxxj + $(this).text()*1;
	})
	pxxj = decimal(pxxj,2)
	$("#pxxj").text(pxxj)
	//计算退费人数
	var tfrs = 0;
	$(".tfrs").each(function(i){
		tfrs = tfrs + $(this).text()*1;
	})
	tfrs = decimal(tfrs,2)
	$("#tfrx").text(tfrs)
	//计算退费
	var tf = 0;
	$(".tf").each(function(i){
		tf = tf + $(this).text()*1;
	})
	tf = decimal(tf,2)
	$("#tf").text(tf)
	//计算扣款
	var kk = 0;
	$(".kk").each(function(i){
		kk = kk + $(this).text()*1;
	})
	kk = decimal(kk,2)
	$("#kk").text(kk)
	//计算退扣小计
	var kkxj = 0;
	$(".kkxj").each(function(i){
		kkxj = kkxj + $(this).text()*1;
	})
	kkxj = decimal(kkxj,2)
	$("#tkxj").text(kkxj)
	//计算科二
	var ke = 0;
	$(".ke").each(function(i){
		ke = ke + $(this).text()*1;
	})
	ke = decimal(ke,2)
	$("#ke").text(ke)
	//计算科三
	var ks = 0;
	$(".ks").each(function(i){
		ks = ks + $(this).text()*1;
	})
	ks = decimal(ks,2)
	$("#ks").text(ks)
	//计算其他杂费
	var zf = 0;
	$(".zf").each(function(i){
		zf = zf + $(this).text()*1;
	})
	zf = decimal(zf,2)
	$("#qtzf").text(zf)
	//计算实收金额
	var sjze = 0;
	$(".sjze").each(function(i){
		sjze = sjze + $(this).text()*1;
	})
	sjze = decimal(sjze,2)
	$("#shze").text(sjze)
	//计算欠费金额
	var qfje = 0;
	$(".qfje").each(function(i){
		qfje = qfje + $(this).text()*1;
	})
	qfje = decimal(qfje,2)
	$("#qfze").text(qfje)
}

//num是要处理的数字  v为要保留的小数位数
function decimal(num,v){
	var vv = Math.pow(10,v);
	return Math.round(num*vv)/vv;
}
</script>
</html>